/*
 * Misc.cpp
 *
 *  Created on:  Jun 12, 2009
 *      Author:  Zach Riggle A37627537
 *      Project: CSE410 Project 2
 */

#include "Misc.h"

const string whitespace = " \t\n\v\f\r";

string trim(string str) {
    // Trim Both leading and trailing spaces
    size_t startpos = str.find_first_not_of(whitespace); // Find the first character position after excluding leading blank spaces
    size_t endpos = str.find_last_not_of(whitespace); // Find the first character position from reverse af

    // if all spaces or empty return an empty string
    if ((string::npos == startpos) || (string::npos == endpos)) {
        str = "";
    } else
        str = str.substr(startpos, endpos - startpos + 1);

    return str;
}
